package UnitTest;

import junit.framework.TestCase;
import DBConnection.MaintenanceStationDB;
import DBConnection.PredictionsDB;
import DBConnection.StatisticStationDB;
import DBConnection.StatisticsDB;
import DBConnection.WeatherStationCollectionDB;
import DBConnection.WeatherStationDB;
import DBConnection.WeatherStationReportDB;
import Form.MaintenanceStationForm;
import Form.StatisticStationForm;
import Form.WeatherStationForm;

public class Test extends TestCase {

	WeatherStationForm ws = new WeatherStationForm("WS01");
	MaintenanceStationForm mSF = new MaintenanceStationForm("MS01");
	StatisticStationForm sSF = new StatisticStationForm("SS01");

	public void testForm() {
		// WeatherStation form
		assertNotNull(ws);
		// MaintenanceStation form
		assertNotNull(mSF);
		// StatisticStation Form
		assertNotNull(sSF);

		// Test cac thanh phan tang xu ly cua tang form
		assertNotNull(ws.getWeatherSH());
		assertNotNull(mSF.getMaintenanceSH());
		assertNotNull(sSF.getStatisticSH());

		// Xac dinh la cung 1 form nhung 2 quyen khac nhau
		assertNotSame(ws, mSF.getMaintenanceSH().getlWeatherSF().get(0));

	}

	public void testLowerLayout() {
		// Khi chay ham thu thap thi co set o nho cho timer
		ws.doTaskCollection();
		// khi set khong duoc null
		assertNotNull(ws.getTimer());
		assertNotNull(ws.getTimer2());

		// Khi chay ham doTaskCheckDamaged() thi timer khong duoc null
		mSF.doTaskCheckDamaged();
		assertNotNull(mSF.getTimer());

		// Set quyen admin sau do kiem tra xem co dung khong
		ws.getWeatherSH().setAdminRole(true);
		assertTrue(ws.getWeatherSH().getWeatherStation().getAdminRole() == 1);

		// Kiem tra cac ham trong tang xu ly cua WeatherStation
		assertNotNull(ws.getWeatherSH().getlReport());
		assertNotNull(ws.getWeatherSH().getWeatherStation());
		assertTrue(ws.getWeatherSH().readFileInput() == true);
		assertNotNull(ws.getWeatherSH().getWeatherSC());
		assertNotNull(ws.getWeatherSH().getlInput());
		assertNotNull(ws.getWeatherSH().getAllReport());

		// Kiem tra cac ham trong tang xu ly cua MaintenanceStation
		assertNotNull(mSF.getMaintenanceSH().getlWeatherSF());
		assertNotNull(mSF.getMaintenanceSH().getTimer());
		assertEquals(0, mSF.getMaintenanceSH().numberStationDamaged());
		assertNotNull(mSF.getMaintenanceSH().getDefaultListModelWSF());
		assertNotNull(mSF.getMaintenanceSH().getMaintenanceS());
		// Sau khi chay ham taskRefreshStation() thi timer != null
		assertNotNull(mSF.getMaintenanceSH().getTimer());
		mSF.getMaintenanceSH().releaseAdminRole();
		// Lay phan tu thu 1 cua list WeatherSF , roi lay quyen admin sau khi da
		// release == 0 hay khong
		assertTrue(mSF.getMaintenanceSH().getlWeatherSF().get(0).getWeatherSH()
				.getWeatherStation().getAdminRole() == 0);
		assertTrue(mSF.getMaintenanceSH().controlAll(true) == true);
		assertTrue(mSF.getMaintenanceSH().addNewStation("WS01") == false);
		assertEquals("MS01", mSF.getMaintenanceSID());

		// Kiem tra cac ham trong tang xu ly cua StatisticStation
		assertNotNull(sSF.getStatisticSH().getStatisicStation());
		assertNotNull(sSF.getStatisticSH().getlPredictions());
		assertNotNull(sSF.getStatisticSH().getlStatistic());
		assertEquals("SS01", sSF.getStatisticSH().getStatisticStationID());
		assertEquals("5-12-2014", sSF.getStatisticSH().getToDay());
		assertNull(sSF.getStatisticSH().getStatisticContent("dasdasdas"));
		assertNull(sSF.getStatisticSH().getPredictionContent("dasdasdas"));

	}

	public void testClassDB() {
		// Lay het du lieu tram bao tri bo vao list
		assertNotNull(new MaintenanceStationDB().findAll());
		// Lay het du lieu Prediction bo vao list
		assertNotNull(new PredictionsDB().findAll());
		// Lay het du lieu Statistic bo vao list
		assertNotNull(new StatisticsDB().findAll());
		// Lay het du lieu StatisticStation bo vao list
		assertNotNull(new StatisticStationDB().findAll());
		// Lay het du lieu WeatherStationCollection bo vao List
		assertNotNull(new WeatherStationCollectionDB().findAll());
		// Lay het du lieu WeatherStation bo vao list
		assertNotNull(new WeatherStationDB().findAll());
		// lay het du lieu WeatherStationReport bo vao list
		assertNotNull(new WeatherStationReportDB().findAll());

		// Test lay du lieu cac tram KHONG co trong database
		assertNull(new WeatherStationDB().find("WS03"));
		assertNull(new MaintenanceStationDB().find("MS02"));
		assertNull(new StatisticStationDB().find("SS02"));

		// Test lay du lieu cac tram CO trong database
		assertNotNull(new WeatherStationDB().find("WS01"));
		assertNotNull(new WeatherStationDB().find("WS02"));
		assertNotNull(new MaintenanceStationDB().find("MS01"));
		assertNotNull(new StatisticStationDB().find("SS01"));
	}

}
